package com.lcj.workflow.bpmn.comment;

import com.lcj.workflow.controller.form.SendPrivateMessageForm;
import com.lcj.workflow.feign.SnmServiceApi;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class NotifyDriverService implements JavaDelegate {
    @Resource
    private SnmServiceApi snmServiceApi;

    public void execute(DelegateExecution delegateExecution) {
        long driverId = Long.parseLong(delegateExecution.getVariable("driverId", String.class));
        long orderId = Long.parseLong(delegateExecution.getVariable("orderId", String.class));
        String result = delegateExecution.getVariable("result", String.class);
        String note = delegateExecution.getVariable("note", String.class);
        SendPrivateMessageForm sendPrivateMessageForm = new SendPrivateMessageForm();
        sendPrivateMessageForm.setReceiverIdentity("message");
        sendPrivateMessageForm.setReceiverId(Long.valueOf(driverId));
        sendPrivateMessageForm.setTtl(Integer.valueOf(259200000));
        sendPrivateMessageForm.setSenderId(Long.valueOf(0L));
        sendPrivateMessageForm.setSenderIdentity("system");
        sendPrivateMessageForm.setSenderName("随行打车");
        String var9 = "订单号:" + orderId + "，该订单的差评申诉";
        if ("同意".equals(result)) {
            var9 = var9 + "成功";
        } else {
            var9 = var9 + "失败";
            if (note != null) {
                var9 = var9 + "。" + var9;
            }
        }

        sendPrivateMessageForm.setMsg(var9);
        this.snmServiceApi.sendPrivateMessageSync(sendPrivateMessageForm);
    }
}
